import 'package:flutter/material.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:jspang/provide/details_info.dart';
import 'package:provider/provider.dart';

class DetailsTabbar extends StatelessWidget {
  const DetailsTabbar({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Selector<DetailsInfoProvide,DetailsInfoProvide>(
      selector: (context,provider) => provider,
      shouldRebuild: (pre,next) => true,
      builder: (context,value,child) {
        var isLeft = Provider.of<DetailsInfoProvide>(context,listen: false).isLeft;
        var isRight = Provider.of<DetailsInfoProvide>(context,listen: false).isRight;
        return Container(
          margin: EdgeInsets.only(top: 15.0),
          child: Row(
            children: <Widget>[
              _myTabbarLeft(context, isLeft),
              _myTabbarRight(context, isRight)
            ],
          )
        );
      },
    );
  }
  //左侧tabbar
  Widget _myTabbarLeft(BuildContext context, bool isLeft) {
    return InkWell(
      onTap: (){
        Provider.of<DetailsInfoProvide>(context,listen: false).changeLeftAndRifht('left');
      },
      child: Container(
        padding: EdgeInsets.all(10.0),
        alignment: Alignment.center,
        width: ScreenUtil().setWidth(375),
        decoration: BoxDecoration(
          color: Colors.white,
          border: Border(
            bottom: BorderSide(width: 1.0,color:isLeft?Colors.pink:Colors.black12)
          )
        ),
        child: Text('详情',style: TextStyle(color: isLeft?Colors.pink:Colors.black),)
      ),
    );
  }

  //右侧tabbar
  Widget _myTabbarRight(BuildContext context, bool isRight) {
    return InkWell(
      onTap: (){
        Provider.of<DetailsInfoProvide>(context,listen: false).changeLeftAndRifht('right');
      },
      child: Container(
        padding: EdgeInsets.all(10.0),
        alignment: Alignment.center,
        width: ScreenUtil().setWidth(375),
        decoration: BoxDecoration(
          color: Colors.white,
          border: Border(
            bottom: BorderSide(width: 1.0,color:isRight?Colors.pink:Colors.black12)
          )
        ),
        child: Text('评论',style: TextStyle(color: isRight?Colors.pink:Colors.black),)
      ),
    );
  }
}